package control;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import bean.Flight;

@Controller
public class FlightControl {

	@Resource
	Dao dao;
	
	@RequestMapping(value="/addFlight",method=RequestMethod.POST)
	public @ResponseBody Flight addFlight(String name, String departureTown, String departureTime, String arrivalTown, String arrivalTime){
		System.out.println("addFlight");
		return dao.addFlight(name, departureTown, Utils.getDateFromString(departureTime), arrivalTown, Utils.getDateFromString(arrivalTime));
	}

	@RequestMapping(value="/removeFlight",method=RequestMethod.GET)	
	public @ResponseBody boolean removeFlight(int idFlight){
		System.out.println("removeFlight");
		return dao.removeFlight(idFlight);
	}

	@RequestMapping(value="/modifiyFlight",method=RequestMethod.GET)	
	public @ResponseBody boolean modifiyFlight(int idxFlight, String name, String departureTown, Date departureTime, String arrivalTown, Date arrivalTime){
		System.out.println("modifiyFlight");
		return dao.modifiyFlight(idxFlight, name, departureTown, departureTime, arrivalTown, arrivalTime);
	}
			
	@RequestMapping(value="/getFlight",method=RequestMethod.GET)		
	public @ResponseBody Flight getFlight(int idxFlight){
		System.out.println("getFlight");
		return dao.getFlight(idxFlight);
	}
		
	@RequestMapping(value="/getFlights",method=RequestMethod.GET)
	public @ResponseBody List<Flight> getFlights(){
		System.out.println("getFlights");
		return dao.getFlights();
	}
}
